package com.example.demo.controller;

import com.example.demo.bean.*;
import com.example.demo.dao.GoodsDao;
import com.example.demo.exception.CodeMsg;
import com.example.demo.exception.GlobalException;
import com.example.demo.result.Result;
import com.example.demo.service.GoodsService;
import com.example.demo.service.OrderService;
import com.sun.org.apache.xpath.internal.operations.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService orderService;

    @Autowired
    GoodsService goodsService;

    @RequestMapping("/findOrderAndGoods")
    @ResponseBody
    public Result<OrderToShow> findOrderAndGoods(User user,Long orderId){
        if (user==null){
            throw new GlobalException(CodeMsg.SERVER_ERROR);
        }
        //去数据库查询orderInfro
        Order orderInfro = orderService.findOrderInfro(orderId);
        //获得goodsId
        Long goodsId = orderInfro.getGoodsId();
        //获得商品的一切有关信息
        GoodsSeckill goods = goodsService.findGoods(goodsId);

        OrderToShow orderToShow=new OrderToShow();
        orderToShow.setUser(user);
        orderToShow.setGoodsSeckill(goods);
        orderToShow.setOrder(orderInfro);

        return Result.success(orderToShow);
    }
}
